﻿@model ForumTopicPageModel
@using Nop.Web.Extensions;
@using Nop.Web.Models.Boards;
@using Nop.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    Html.AddTitleParts(Model.Subject);
}
<script type="text/javascript">
    function handleTopicWatch(context) {
        $('#watch-topic-top').text(context.Text);
        $('#watch-topic-bottom').text(context.Text);
    }
</script>
@Html.Action("ForumBreadcrumb", new { forumTopicId = Model.Id })
@Html.Partial("_SearchBox")
<div class="page forum-topic-page">
    <div class="title">
        <h2 class="topic-name">
            <span>@Model.Subject</span></h2>
    </div>
    <div class="topic-header">
        <div class="topic-options">
            @if (Model.IsCustomerAllowedToEditTopic)
            {
                @Html.RouteLink(T("Forum.EditTopic").Text, "TopicEdit", new { id = Model.Id }, new { @class = "edit-topic-link-button" })
            }
            @if (Model.IsCustomerAllowedToDeleteTopic)
            {                
                @Html.RouteLink(T("Forum.DeleteTopic").Text, "TopicDelete", new { id = Model.Id }, new { onClick = String.Format("return confirm('{0}');", T("Common.AreYouSure").Text), @class = "delete-topic-link-button" })
            }
            @if (Model.IsCustomerAllowedToMoveTopic)
            {
                @Html.RouteLink(T("Forum.MoveTopic").Text, "TopicMove", new { id = Model.Id }, new { @class = "move-topic-link-button" })
            }
            @Html.RouteLink(T("Forum.Reply").Text, "PostCreate", new { id = Model.Id }, new { @class = "reply-topic-link-button" })
            @if (Model.IsCustomerAllowedToSubscribe)
            {
                @Ajax.RouteLink(Model.WatchTopicText,
                                "TopicWatch",
                                new { id = Model.Id },
                                new AjaxOptions { HttpMethod = "Post", OnSuccess = "handleTopicWatch" },
                                new { id = "watch-topic-top", @class = "watch-topic-link-button" })
            }
        </div>
        <div class="pager upper">
            @{
                var pager = Html.Pager(new PagerModel()
                {
                    PageSize = Model.PostsPageSize,
                    TotalRecords = Model.PostsTotalRecords,
                    PageIndex = Model.PostsPageIndex,
                    ShowTotalSummary = false,
                    RouteActionName = "TopicSlugPaged",
                    UseRouteLinks = true,
                    RouteValues = new RouteValues { id = Model.Id, slug = Model.SeName }
                });
            }
            @pager
        </div>
    </div>
    <div class="posts">
        @foreach (var post in @Model.ForumPostModels)
        {
            Html.RenderPartial("_ForumPost", post);
        }
    </div>
</div>
<div class="topic-footer">
    <div class="topic-options">
        @Html.RouteLink(T("Forum.Reply").Text, "PostCreate", new { id = Model.Id }, new { @class = "reply-topic-link-button" })
        @if (Model.IsCustomerAllowedToSubscribe)
        {
            @Ajax.RouteLink(Model.WatchTopicText,
                            "TopicWatch",
                            new { id = Model.Id },
                            new AjaxOptions { HttpMethod = "Post", OnSuccess = "handleTopicWatch" },
                            new { id = "watch-topic-bottom", @class = "watch-topic-link-button" })
        }
    </div>
    <div class="pager lower">
        @pager
    </div>
</div>
